<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.io.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!
	//request.setCharacterEncoding("UTF-8");
	String service_name="";       
 	String service_price="";
    String service_number="";
%>
<%
//  	boolean isMultipart = ServletFileUpload.isMultipartContent(request);
//  	if (!isMultipart) {} 
//  	else {
//  		FileItemFactory factory = new DiskFileItemFactory();
//    		ServletFileUpload upload = new ServletFileUpload(factory);
//    		List items = null;
//    		try {
//    			items = upload.parseRequest(request);
//    		} catch (FileUploadException e) {
//    			e.printStackTrace();
//    		}		
//    	Iterator itr = items.iterator();
//    	while (itr.hasNext()) {
//    		FileItem item = (FileItem) itr.next();
//    		if (item.isFormField())
//    		{
//    			String tmp = item.getFieldName();
//             String value = new String(item.getString().getBytes("ISO-8859-1"), "UTF-8");
//             if(tmp.equals("service_name")) service_name=value;
//            	if(tmp.equals("service_price")) service_price=value;                         
// 			if(tmp.equals("service_number")) service_number=value;                         
//    		} else
//    		{
//     		}
//    		}
//    	}
 	
	Class.forName("com.mysql.jdbc.Driver");
	Connection con = null;
	Statement smt = null;
	ResultSet rst = null;
	String SQL = null;
	String service_id = request.getParameter("service_id");
	int i = 0;
// 	if (service_name.length() == 0 || service_price.length() == 0 || service_number.length() == 0) response.sendRedirect("add_service.jsp");
// 	else
	try {
		String username = "root";
		String password = "Vietyeutam1112";
		String url = "jdbc:mysql://127.0.0.1:3306/ghmotel?useUnicode=true&characterEncoding=UTF-8";
		con = DriverManager.getConnection(url, username, password);
		System.out.println("Da ket noi CSDL");
		smt = con.createStatement();
		rst = smt.executeQuery("select * from service");
		while (rst.next()) i++;
		System.out.println(i);
		i++;
		//SQL = "INSERT INTO product VALUES ('%s','%s','%s')";
// 		SQL = String.format("INSERT INTO service(service_name,service_price,service_number) VALUES ('%s',%s,%s)",service_name,service_price,service_number);
		System.out.println(SQL);
		smt.execute("INSERT INTO test VALUES ('"+service_id+"')");
		con.close();
		System.out.println("Dong ket noi");
		response.sendRedirect("service_manager.jsp");
	}
	catch (Exception e) {
		e.printStackTrace();
		System.out.println("KHONG KET NOI DUOC");
	}

%>
</body>
</html>